/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.hibernate.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "CHANNELS")
public class Channels extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "Channels";
	public static final String ALIAS_ID = "ID";
	public static final String ALIAS_USER_ID = "用户ID";
	public static final String ALIAS_LINKMAN = "联系人姓名";
	public static final String ALIAS_NAME = "渠道名称";
	public static final String ALIAS_EMAIL = "联系人Email";
	public static final String ALIAS_MOBILE = "联系人手机";
	public static final String ALIAS_PHONE = "联系人电话";
	public static final String ALIAS_STATUS = "状态，1正常，2删除，默认为1";
	public static final String ALIAS_CREATION_TIME = "添加时间";
	
	//date formats
	public static final String FORMAT_CREATION_TIME = DATE_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long id;
	@NotBlank @Length(max=100)
	private java.lang.String linkman;
	@NotBlank @Length(max=100)
	private java.lang.String name;
	@NotBlank @Length(max=50)
	private java.lang.String email;
	@Length(max=20)
	private java.lang.String mobile;
	@Length(max=20)
	private java.lang.String phone;
	private String phoneArea;
	private String phoneExt;
	@NotBlank @Length(max=1)
	private java.lang.String status;
	@NotNull 
	private java.util.Date creationTime;

	private Long websiteAmount;
	@Length(max=255)
	private String otherCode;	

	private Long poolId;

	public Channels(){
	}

	public Channels(
		Long id
	){
		this.id = id;
	}


	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	

	
	public void setPoolId(Long poolId) {
		this.poolId = poolId;
	}
	
	@Column(name = "POOL_ID",nullable = false)
	public Long getPoolId() {
		return poolId;
	}
	
	@Column(name = "NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	
	public java.lang.String getName() {
		return name;
	}

	public void setName(java.lang.String name) {
		this.name = name;
	}

	@Column(name = "LINKMAN", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public java.lang.String getLinkman() {
		return this.linkman;
	}
	
	public void setLinkman(java.lang.String value) {
		this.linkman = value;
	}
	
	@Column(name = "EMAIL", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public java.lang.String getEmail() {
		return this.email;
	}
	
	public void setEmail(java.lang.String value) {
		this.email = value;
	}
	
	@Column(name = "MOBILE", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getMobile() {
		return this.mobile;
	}
	
	public void setMobile(java.lang.String value) {
		this.mobile = value;
	}
	
	@Column(name = "PHONE", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public java.lang.String getPhone() {
		return this.phone;
	}
	
	public void setPhone(java.lang.String value) {
		this.phone = value;
	}
	
	@Column(name = "STATUS", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getStatus() {
		return this.status;
	}
	
	public void setStatus(java.lang.String value) {
		this.status = value;
	}
	
	@Transient
	public String getCreationTimeString() {
		return DateConvertUtils.format(getCreationTime(), FORMAT_CREATION_TIME);
	}
	public void setCreationTimeString(String value) {
		setCreationTime(DateConvertUtils.parse(value, FORMAT_CREATION_TIME,java.util.Date.class));
	}
	
	@Column(name = "CREATION_TIME", unique = false, nullable = false, insertable = true, updatable = true, length = 7)
	public java.util.Date getCreationTime() {
		return this.creationTime;
	}
	
	public void setCreationTime(java.util.Date value) {
		this.creationTime = value;
	}
	
	
	@SuppressWarnings("rawtypes")
	private Set websites = new HashSet(0);
	public void setWebsites(Set<Website> website){
		this.websites = website;
	}
	
	@SuppressWarnings("unchecked")
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY , mappedBy = "channels")
	@OrderBy("name")
	public Set<Website> getWebsites() {
		return websites;
	}
	
	@Transient
	public String getPhoneArea() {
		return phoneArea;
	}

	public void setPhoneArea(String phoneArea) {
		this.phoneArea = phoneArea;
	}
	@Transient
	public String getPhoneExt() {
		return phoneExt;
	}

	public void setPhoneExt(String phoneExt) {
		this.phoneExt = phoneExt;
	}
	
	@Column(name = "WEBSITE_AMOUNT", unique = false, insertable = true, updatable = true, length = 20)
	public Long getWebsiteAmount() {
		return websiteAmount;
	}

	public void setWebsiteAmount(Long websiteAmount) {
		this.websiteAmount = websiteAmount;
	}
	@Column(name = "OTHER_CODE", unique = false, nullable = true, insertable = true, updatable = true, length = 255)
	public String getOtherCode() {
		return this.otherCode;
	}
	
	public void setOtherCode(String value) {
		this.otherCode = value;
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "媒体渠道";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getName();
	}
}

